
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:furaha_mkopo/commonTool/fm_color_tool.dart';
import 'package:furaha_mkopo/manager/fm_global_manager.dart';
import 'package:furaha_mkopo/page/home/fm_home_page.dart';
import 'package:furaha_mkopo/page/me/fm_me_page.dart';
import 'package:get/get.dart';

import 'fm_tab_controller.dart';

class FMTabPage extends StatefulWidget {

  const FMTabPage({super.key});

  @override
  State<FMTabPage> createState() => _FMTabPageState();
}

class _FMTabPageState extends State<FMTabPage> with SingleTickerProviderStateMixin {

  final controller = Get.put(FMTabController());

  @override
  void initState() {
    super.initState();
    FMGlobalManager().context = context;
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<FMTabController>(
      builder: (controller) {
        return Scaffold(
          body: TabBarView(
            physics: const NeverScrollableScrollPhysics(),
            controller: controller.tabController,
            children: const [
              FMHomePage(),
              FMMePage(),
            ],
          ),
            bottomNavigationBar: BottomAppBar(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: <Widget>[
                  _bottomItem("tab_home", "Home",0),
                  _bottomItem("tab_me", "Me",1),
                ],
              ),
            )
        );
    });
  }

  Widget _bottomItem(String tabImageName,String labelName,int index) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: () => controller.onItemTapped(index),
      child: Container(
        width: 100,
        color: Colors.transparent,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            const SizedBox(height: 10),
            customItem(tabImageName,index),
            const SizedBox(height: 5),
            Text(
              labelName,
              style: TextStyle(
                fontSize: 10, // 自定义字体大小
                color: controller.selectIndex == index ? FMColorTool.color("#000000") : FMColorTool.color("#ABB2A6"),
              ),
            ),
            const SizedBox(height: 5),
          ],
        ),
      ),
    );
  }

  Widget customItem(String iconName,int index) {
    String imageName = index == controller.selectIndex ? "assets/tab/${iconName}_selected.png" : "assets/tab/$iconName.png";
    return Image.asset(imageName,width: 25,height: 25,);
  }
}
